package engine.core
{
	import flash.display.*;
	import flash.events.*;
	
	public class RxKeyboard
	{
		private static var s_eventObject:InteractiveObject = null;
		private static var s_lock:Boolean = false;
		private static var s_ignoreFocus:Boolean = false;
		private static var s_keyDown:Vector.<Boolean> = new Vector.<Boolean>(256);
		private static var s_keyPressed:Object = {};
		public static const KEY_BACKSPACE:uint = 8;
		public static const KEY_TAB:uint = 9;
		public static const KEY_ENTER:uint = 13;
		public static const KEY_SHIFT:uint = 16;
		public static const KEY_CTRL:uint = 17;
		public static const KEY_ALT:uint = 18;
		public static const KEY_CAPSLOCK:uint = 20;
		public static const KEY_ESC:uint = 27;
		public static const KEY_SPACE:uint = 32;
		public static const KEY_0:uint = 48;
		public static const KEY_1:uint = 49;
		public static const KEY_2:uint = 50;
		public static const KEY_3:uint = 51;
		public static const KEY_4:uint = 52;
		public static const KEY_5:uint = 53;
		public static const KEY_6:uint = 54;
		public static const KEY_7:uint = 55;
		public static const KEY_8:uint = 56;
		public static const KEY_9:uint = 57;
		public static const KEY_A:uint = 65;
		public static const KEY_B:uint = 66;
		public static const KEY_C:uint = 67;
		public static const KEY_D:uint = 68;
		public static const KEY_E:uint = 69;
		public static const KEY_F:uint = 70;
		public static const KEY_G:uint = 71;
		public static const KEY_H:uint = 72;
		public static const KEY_I:uint = 73;
		public static const KEY_J:uint = 74;
		public static const KEY_K:uint = 75;
		public static const KEY_L:uint = 76;
		public static const KEY_M:uint = 77;
		public static const KEY_N:uint = 78;
		public static const KEY_O:uint = 79;
		public static const KEY_P:uint = 80;
		public static const KEY_Q:uint = 81;
		public static const KEY_R:uint = 82;
		public static const KEY_S:uint = 83;
		public static const KEY_T:uint = 84;
		public static const KEY_U:uint = 85;
		public static const KEY_V:uint = 86;
		public static const KEY_W:uint = 87;
		public static const KEY_X:uint = 88;
		public static const KEY_Y:uint = 89;
		public static const KEY_Z:uint = 90;
		public static const KEY_SEMICOLON:uint = 186;
		public static const KEY_EQUAL:uint = 187;
		public static const KEY_COMMA:uint = 188;
		public static const KEY_SUBTRACT:uint = 189;
		public static const KEY_DECIMAL:uint = 190;
		public static const KEY_DIVIDE:uint = 191;
		public static const KEY_TILDA:uint = 192;
		public static const KEY_LEFT_BRACKET:uint = 219;
		public static const KEY_BACK_SLASH:uint = 220;
		public static const KEY_RIGHT_BRACKET:uint = 221;
		public static const KEY_QUOTE:uint = 222;
		public static const KEY_NUMPAD0:uint = 96;
		public static const KEY_NUMPAD1:uint = 97;
		public static const KEY_NUMPAD2:uint = 98;
		public static const KEY_NUMPAD3:uint = 99;
		public static const KEY_NUMPAD4:uint = 100;
		public static const KEY_NUMPAD5:uint = 101;
		public static const KEY_NUMPAD6:uint = 102;
		public static const KEY_NUMPAD7:uint = 103;
		public static const KEY_NUMPAD8:uint = 104;
		public static const KEY_NUMPAD9:uint = 105;
		public static const KEY_NUMPAD_MULTIPLY:uint = 106;
		public static const KEY_NUMPAD_ADD:uint = 107;
		public static const KEY_NUMPAD_SUBTRACT:uint = 109;
		public static const KEY_NUMPAD_DECIMAL:uint = 110;
		public static const KEY_NUMPAD_DIVIDE:uint = 111;
		public static const KEY_PAUSE:uint = 19;
		public static const KEY_PAGE_UP:uint = 33;
		public static const KEY_PAGE_DOWN:uint = 34;
		public static const KEY_END:uint = 35;
		public static const KEY_HOME:uint = 36;
		public static const KEY_INSERT:uint = 45;
		public static const KEY_DELETE:uint = 46;
		public static const KEY_SCROLL_LOCK:uint = 145;
		public static const KEY_ARROW_LEFT:uint = 37;
		public static const KEY_ARROW_UP:uint = 38;
		public static const KEY_ARROW_RIGHT:uint = 39;
		public static const KEY_ARROW_DOWN:uint = 40;
		public static const KEY_F1:uint = 112;
		public static const KEY_F2:uint = 113;
		public static const KEY_F3:uint = 114;
		public static const KEY_F4:uint = 115;
		public static const KEY_F5:uint = 116;
		public static const KEY_F6:uint = 117;
		public static const KEY_F7:uint = 118;
		public static const KEY_F8:uint = 119;
		public static const KEY_F9:uint = 120;
		public static const KEY_F10:uint = 121;
		public static const KEY_F11:uint = 122;
		public static const KEY_F12:uint = 123;
		
		public function RxKeyboard()
		{
		}
		
		public static function Initialize(eventObject:InteractiveObject) : void
		{
			s_eventObject = eventObject;
			s_eventObject.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			s_eventObject.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
		}
		
		public static function onKeyDown(event:KeyboardEvent) : void
		{
			if (event.currentTarget.root.focus != null && s_ignoreFocus == false)
			{
	
			}
			s_keyDown[event.keyCode] = true;
			if (!s_keyPressed[event.keyCode])
			{
				s_keyPressed[event.keyCode] = 0;
			}

			s_keyPressed[event.keyCode] = s_keyPressed[event.keyCode] + 1;
		}
		
		public static function onKeyUp(event:KeyboardEvent) : void
		{
			if (event.currentTarget.root.focus != null && s_ignoreFocus == false)
			{
	
			}
			delete s_keyPressed[event.keyCode];
			s_keyDown[event.keyCode] = false;
		}
		
		public static function isDown(param1:int) : Boolean
		{
			if (s_lock == true)
			{
				return false;
			}
			return s_keyDown[param1];
		}
		
		public static function isPressed(param1:int) : Boolean
		{
			if (s_lock == true)
			{
				return false;
			}
			return s_keyPressed[param1] == 1;
		}
		
		public static function Reset() : void
		{
			var _loc_1:String = null;
			for (_loc_1 in s_keyPressed)
			{
				
				if (s_keyPressed[_loc_1] > 0)
				{
					var _loc_4:* = s_keyPressed;
					var _loc_5:* = _loc_1;
					var _loc_6:* = s_keyPressed[_loc_1] + 1;
					_loc_4[_loc_5] = _loc_6;
				}
			}
		}
		
		public static function lock() : void
		{
			s_lock = true;
		}
		
		public static function unlock() : void
		{
			s_lock = false;
		}
		
		public static function islocked() : Boolean
		{
			return s_lock;
		}
		
		public static function ignoreFocus(param1:Boolean) : void
		{
			s_ignoreFocus = param1;
		}
		
		public static function SetPlaybackValues(param1:Boolean, param2:Boolean, param3:Boolean, param4:Boolean, param5:Boolean, param6:Boolean) : void
		{
			s_keyDown[KEY_1] = param1;
			s_keyDown[KEY_2] = param2;
			s_keyDown[KEY_3] = param3;
			s_keyDown[KEY_4] = param4;
			s_keyDown[KEY_5] = param5;
			s_keyDown[KEY_6] = param6;
		}
	}
}